package @actionPackage@.util;

import java.util.List;

import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.framework.EntityQuery;

public abstract class GenericEntityHome<E> extends EntityHome<E> {

	private EntityQuery<E> entityList;

	public String remove() {
		String remove = super.remove();
		refresh();
		this.clearInstance();
		return remove;
	}
	public String remove(E instance) {
		this.setInstance(instance);
		String remove = super.remove();
		refresh();
		this.clearInstance();
		return remove;
	}

	@Override
	public String persist() {
		String persist = super.persist();
		refresh();
		return persist;
	}

	@Override
	public String update() {
		String update = super.update();
		refresh();

		return update;
	}

	public void refresh() {
		entityList.refresh();
	}

	public void cancel() {
		clearInstance();
	}

	public void sec(E instance) {
		this.setInstance(instance);
	}

	public List<E> getResultList() {
		return getEntityManager().createQuery(
				"from " + getInstance().getClass().getSimpleName())
				.getResultList();
	}

	public void setEntityList(EntityQuery<E> entityList) {
		this.entityList = entityList;
	}
	public EntityQuery<E> getEntityList() {
		return entityList;
	}

}
